home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pcroct89.arc / PCTOCT.ARC / PRTSCR1.ASM < prev    next >
Assembly Source File  |  1990-03-21  |  6KB  |  238 lines

  1. Comment |
  2.    First module in the replacement PrintScreen program.  This module
  3.    contains the code which intercepts Shift-PrtScr from the keyboard,
  4.    determines the current video mode, printer address, and calls the
  5.    appropriate routine in Listing 2.  It also contains the installation
  6.    code.
  7.    Save as  PRTSCR1.ASM
  8.    Compile: MASM /Ml PRTSCR;
  9.      or
  10.             TASM /Ml PRTSCR
  11.     |
  12.  
  13. ;Remove the comment mark from the next line if you are using TASM
  14. ;TASM    equ    1
  15.  
  16. Ifdef    TASM
  17.     QUIRKS
  18.     MASM51
  19. Endif
  20.  
  21.     .MODEL SMALL,C
  22.  
  23. extrn    textmode:near, lo_res:near, med_res:near, hi_res:near
  24. extrn    cga_4:near, cga_6:near, ega_clr:near, ega_mono:near
  25.  
  26.     .STACK 100h
  27.  
  28.     .DATA
  29.         db    200h dup (?)
  30. newstk        equ    $        ;Start of ISR stack
  31. base_port    dw    ?
  32.  
  33. public vidmode, vidcols, vidrows, vidseg, vidoff, vidpage
  34. vidmode        dw    ?        ;Variables describing 
  35. vidcols        dw    ?        ;  current video state
  36. vidrows        dw    ?
  37. vidseg        dw    ?
  38. vidoff        dw    ?
  39. vidpage        dw    ?
  40.  
  41. ;  Call table for print-screen routines
  42. vidroutine    dw    offset textmode, offset textmode  ;Modes 0,1
  43.         dw    offset textmode, offset textmode  ;Modes 2,3
  44.         dw    offset lo_res,   offset lo_res      ;Modes 4,5
  45.         dw    offset med_res,  offset textmode  ;Modes 6,7
  46.         dw    5 dup (offset none)          ;Modes 8-0C
  47.         dw    offset lo_res,   offset med_res   ;Modes 0D,0E
  48.         dw    offset hi_res,   offset hi_res    ;Modes 0F,10
  49.  
  50. Ifndef    TASM
  51. public _acrtused
  52. _acrtused    dw    ?        ;Keep MSC/QC from loading startup
  53.                     ;code.
  54. Endif
  55.  
  56. signon        db    13,10,"PC Resource's PrintScreen Program is installed."
  57.         db    13,10,"You can now print graphics and text."
  58.         db    13,10,"$"
  59.  
  60.     .CODE
  61. ;----------
  62. ;  CS-based data locations
  63. ;----------
  64.  
  65. old_sp        dw    ?
  66. old_ss        dw    ?
  67. start_flag    db    0
  68.  
  69. ;------------
  70. ;  This becomes the new Int 05h
  71. ;  and intercepts Shift-Prtscr keypresses.
  72. ;  It must change to our local stack, save
  73. ;  registers, and restore everything when
  74. ;  we're done.
  75. ;------------
  76. new_int5    proc
  77.     test    cs:start_flag,-1    ;Already here?
  78.     jnz    int5_exit        ;Yes -- just leave
  79.     mov    cs:start_flag,1        ;Show we've started
  80.     push    ax            ;Save AX register for return
  81.     cli                ;No interrupts
  82.     mov    cs:[old_ss],ss        ;Save the stack
  83.     mov    cs:[old_sp],sp
  84.     mov    ax,@data        ;Move to our stack
  85.     mov    ss,ax
  86.     mov    sp,offset newstk
  87.     sti                ;Allow interrupts
  88.  
  89.     push    bx            ;Save all registers
  90.     push    cx
  91.     push    dx
  92.     push    bp
  93.     push    di
  94.     push    si
  95.     push    ds
  96.     push    es
  97.  
  98.     mov    ax,@data        ;Set DS to our data
  99.     mov    ds,ax
  100.     call    setup            ;And start to work
  101.  
  102.     pop    es            ;Recover registers
  103.     pop    ds
  104.     pop    si
  105.     pop    di
  106.     pop    bp
  107.     pop    dx
  108.     pop    cx
  109.     pop    bx
  110.  
  111.     cli                ;No interrupts during
  112.     mov    ss,cs:[old_ss]        ;  stack switch
  113.     mov    sp,cs:[old_sp]
  114.     sti                ;Allow interrupts
  115.     pop    ax            ;Get original AX
  116.     mov    start_flag,0        ;Show that we're leaving
  117. int5_exit:
  118.     iret                ;We're done
  119. new_int5    endp
  120.  
  121. ;------------
  122. ;  Read video and printer info from BIOS RAM,
  123. ;  then call the correct PrtScr routine.
  124. ;------------
  125. setup    proc
  126.     mov    ax,40h            ;ES ==> ROM BIOS data
  127.     mov    es,ax
  128.     mov    dx,es:[8]           ;Get printer port addr.
  129.     mov    base_port,dx        ;Save it
  130.     or    dx,dx            ;Is a printer attached?
  131.     jz    exit            ;No -- forget it
  132.     inc    dx            ;DX ==> status port
  133.     in    al,dx            ;Read status
  134.     and    al,1000B        ;Test bit 3
  135.     jz    exit            ;Error -- skip everything
  136.     mov    al,es:[49h]        ;Get video mode
  137.     cbw                ;Change byte to word
  138.     mov    vidmode,ax        ;Save mode
  139.     cmp    ax,10h            ;Is it okay?
  140.     ja    exit            ;VGA/MCGA special: exit
  141.     mov    ax,es:[4ah]        ;Get display columns
  142.     mov    vidcols,ax        ;  and save
  143.     mov    al,es:[84h]        ;Get display rows
  144.     or    al,al            ;Is it 0?
  145.     jnz    @F            ;No -- go
  146.     mov    al,24            ;Else assume default
  147.   @@:    cbw                ;Make into word
  148.       mov    vidrows,ax        ;  and save it
  149.     cmp    vidmode,7        ;Monochrome mode?
  150.     jne    @F            ;No -- go
  151.     mov    vidseg,0b000h        ;Yes -- video base at B000
  152.     jmp    short setup_1        ;Skip other tests
  153.   @@:    jg    @F            ;Go if EGA graphics
  154.       mov    vidseg,0b800h        ;Video base for CGA & color text
  155.     jmp    short setup_1
  156.   @@:    mov    vidseg,0a000h        ;Video base for EGA/VGA graphics
  157. setup_1:
  158.     mov    ax,es:[4eh]        ;Video offset address
  159.     mov    vidoff,ax        ;  and save it
  160.     mov    bx,vidmode        ;Get mode back
  161.     add    bx,bx            ;* 2 for table offset
  162.     add    bx,offset vidroutine    ;Add table address
  163.     call    [bx]            ;Call routine
  164. exit:    ret                ;We're done
  165. setup    endp
  166.  
  167. ;------------
  168. ;  Dummy routine if a PCjr/Tandy 1000
  169. ;  or illegal video mode appears to be
  170. ;  active
  171. ;------------
  172. none    proc
  173.     ret
  174. none    endp
  175.  
  176. ;------------
  177. ;  Send a byte to the printer
  178. ;  If the printer signals an error,
  179. ;  simply return with the byte unsent.
  180. ;  If the printer is busy, wait for it.
  181. ;------------
  182. prt_out    proc    near uses dx, char:word
  183.     mov    dx,base_port
  184.     inc    dx            ;DX ==> status port
  185.   @@:    in    al,dx            ;Get status
  186.       test    al,1000b        ;Error?
  187.     jz    exit            ;Yes -- forget it
  188.     test    al,80h            ;Busy?
  189.     jz    @B            ;Yes -- wait til ready
  190.     mov    ax,char            ;Get char to print
  191.     dec    dx            ;DX ==> data port
  192.     out    dx,al            ;Send character
  193.     inc    dx
  194.     inc    dx            ;DX ==> output control port
  195.     mov    al,1101b        ;Bit 0 is strobe bit
  196.     out    dx,al            ;Turn strobe on
  197.     dec    al            ;(now it's 1100b)
  198.     out    dx,al            ;Turn strobe off
  199. exit:    ret
  200. prt_out        endp
  201.  
  202. ;------------
  203. ;  Send a value to a specific port
  204. ;  on the EGA Graphics Controller chip
  205. ;------------
  206. gc_out    proc    near index:word, value:word
  207.     mov    dx,3ceh            ;Graphics controller port
  208.     mov    ax,index        ;Index in AL
  209.     mov    bx,value        ;Value in BL
  210.     mov    ah,bl            ;Value in AH
  211.     out    dx,ax            ;Send it out
  212.     ret
  213. gc_out        endp
  214.  
  215. ;------------
  216. ;  Install the Print-Screen program in
  217. ;  memory and exit.  Note that this does
  218. ;  not check to see if it is already installed.
  219. ;  (You may want to add that).
  220. ;------------
  221.  
  222. install    proc    near
  223.     mov    ax,@code        ;Get code segment
  224.     mov    ds,ax            ;  into DS
  225.     mov    dx,offset new_int5    ;Get new Int 5 address
  226.     mov    ax,2505h        ;Set as new Int 5
  227.     int    21h
  228.     mov    ax,@data        ;Now get data segment
  229.     mov    ds,ax            ;  into DS
  230.     mov    dx,offset signon    ;DS:DX ==> sign-on message
  231.     mov    ah,9            ;Print a string
  232.     int    21h            ;Tell the world
  233.     mov    dx,0abh            ;Paragraphs to keep (from MAP file)
  234.     mov    ax,3100h        ;Terminate & stay resident
  235.     int    21h
  236. install    endp
  237.     end    install
  238.